package com.itheima.controller;

import com.itheima.pojo.Article;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Reservation;
import com.itheima.pojo.Result;
import com.itheima.pojo.vo.ReservationVo;
import com.itheima.service.ReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/reservation")
public class ReservationController {
    @Autowired
    private ReservationService reservationService;

    /**
     *新增文章
     */
    @PostMapping
    public Result add(@RequestBody @Validated Reservation reservation) {
        reservationService.add(reservation);
        return Result.success();
    }

    /**
     *分页查询文章
     */
    @GetMapping
    public Result<PageBean<ReservationVo>> list(
            Integer pageNum,
            Integer pageSize,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String username,
            @RequestParam(required = false) Integer status
    ) {
        PageBean<ReservationVo> pb=reservationService.list(pageNum,pageSize,name,username,status);
        return Result.success(pb);
    }
    /**
     * 更新状态
     */
    @PutMapping
    public Result updateStatus(@RequestParam("id") Integer id ,@RequestParam("status") Integer status){
        int a=1;
        reservationService.updateStatus(id,status);
        return Result.success();
    }

    /**
     * 删除文章
     */
    @DeleteMapping
    public Result delete(@RequestParam Integer id){
        reservationService.delete(id);
        return Result.success();
    }

}
